home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / apt-xapian-index / plugins / sizes.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  4.4 KB  |  117 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import apt
  5. import xapian
  6. import os
  7. import os.path as os
  8.  
  9. class Sizes:
  10.     
  11.     def info(self):
  12.         '''
  13.         Return general information about the plugin.
  14.  
  15.         The information returned is a dict with various keywords:
  16.          
  17.          timestamp (required)
  18.            the last modified timestamp of this data source.  This will be used
  19.            to see if we need to update the database or not.  A timestamp of 0
  20.            means that this data source is either missing or always up to date.
  21.          values (optional)
  22.            an array of dicts { name: name, desc: description }, one for every
  23.            numeric value indexed by this data source.
  24.  
  25.         Note that this method can be called before init.  The idea is that, if
  26.         the timestamp shows that this plugin is currently not needed, then the
  27.         long initialisation can just be skipped.
  28.         '''
  29.         file = apt.apt_pkg.Config.FindFile('Dir::Cache::pkgcache')
  30.         return dict(timestamp = os.path.getmtime(file), values = [
  31.             dict(name = 'installedsize', desc = 'installed size'),
  32.             dict(name = 'packagesize', desc = 'package size')])
  33.  
  34.     
  35.     def doc(self):
  36.         '''
  37.         Return documentation information for this data source.
  38.  
  39.         The documentation information is a dictionary with these keys:
  40.           name: the name for this data source
  41.           shortDesc: a short description
  42.           fullDoc: the full description as a chapter in ReST format
  43.         '''
  44.         return dict(name = 'Sizes', shortDesc = 'package sizes indexed as values', fullDoc = '\n            The Sizes data source indexes the package size and the installed\n            size as the ``packagesize`` and ``installedsize`` Xapian values.\n            ')
  45.  
  46.     
  47.     def init(self, info, progress):
  48.         '''
  49.         If needed, perform long initialisation tasks here.
  50.  
  51.         info is a dictionary with useful information.  Currently it contains
  52.         the following values:
  53.  
  54.           "values": a dict mapping index mnemonics to index numbers
  55.  
  56.         The progress indicator can be used to report progress.
  57.         '''
  58.         values = info['values']
  59.         self.val_inst_size = values.get('installedsize', -1)
  60.         self.val_pkg_size = values.get('packagesize', -1)
  61.  
  62.     
  63.     def index(self, document, pkg):
  64.         '''
  65.         Update the document with the information from this data source.
  66.  
  67.         document  is the document to update
  68.         pkg       is the python-apt Package object for this package
  69.         '''
  70.         
  71.         try:
  72.             instSize = pkg.installedSize
  73.             pkgSize = pkg.packageSize
  74.         except:
  75.             return None
  76.  
  77.         if self.val_inst_size != -1:
  78.             document.add_value(self.val_inst_size, xapian.sortable_serialise(instSize))
  79.         
  80.         if self.val_pkg_size != -1:
  81.             document.add_value(self.val_pkg_size, xapian.sortable_serialise(pkgSize))
  82.         
  83.  
  84.     
  85.     def indexDeb822(self, document, pkg):
  86.         '''
  87.         Update the document with the information from this data source.
  88.  
  89.         This is alternative to index, and it is used when indexing with package
  90.         data taken from a custom Packages file.
  91.  
  92.         document  is the document to update
  93.         pkg       is the Deb822 object for this package
  94.         '''
  95.         
  96.         try:
  97.             instSize = int(pkg['Installed-Size'])
  98.             pkgSize = int(pkg['Size'])
  99.         except:
  100.             return None
  101.  
  102.         if self.val_inst_size != -1:
  103.             document.add_value(self.val_inst_size, xapian.sortable_serialise(instSize))
  104.         
  105.         if self.val_pkg_size != -1:
  106.             document.add_value(self.val_pkg_size, xapian.sortable_serialise(pkgSize))
  107.         
  108.  
  109.  
  110.  
  111. def init():
  112.     '''
  113.     Create and return the plugin object.
  114.     '''
  115.     return Sizes()
  116.  
  117.